package com.xjzd.practice.statemachine;

public class OrderDemo {

    public static void main(String[] args) {
        OrderState currentState = OrderState.PENDING_PAYMENT;
        System.out.println("初始化状态: " + currentState.getDesc());

        try {
            currentState = StateMachine.transition(currentState, OrderEvent.PAY);
            System.out.println("支付后状态: " + currentState.getDesc());

            currentState = StateMachine.transition(currentState, OrderEvent.SHIP);
            System.out.println("发货后状态: " + currentState.getDesc());

            currentState = StateMachine.transition(currentState, OrderEvent.CONFIRM_RECEIPT);
            System.out.println("确认收货后状态: " + currentState.getDesc());

            currentState = OrderState.PAID;
            StateMachine.transition(currentState, OrderEvent.CANCEL);
        } catch (NoSuchFieldException | IllegalAccessException | InstantiationException e) {
            throw new RuntimeException(e);
        }
    }
}
